//
//  Man.m
//  07-内存管理
//
//  Created by Snow on 16/7/12.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "Man.h"

@implementation Man
//assign修饰的属性的setter方法
- (void)setNumber:(NSInteger)number
{
    _number = number;
}
//retain修饰的属性的setter方法
- (void)setName:(NSString *)name
{
if(_name != name) {
    [_name release];
    _name = [name retain];
  }
}
//copy修饰下的属性的setter方法
- (void)setMId:(NSString *)mId
{
    if (_mId != mId) {
        [mId release];
        _mId = [mId copy];
        
    }
}




- (void)dealloc
{
    //释放所有的属性生成的成员变量(语义使用retain,copy的需要释放)
    [_name release];
    [_mId release];
    [_seual release];
    [_mDescription release];
    [_gayBoy release];
    [super dealloc];
}
//协议方法的实现 是签订者的实现(@implementation)中
- (void)sayHello
{
    NSLog(@"Hello");
}

- (void)sayGoodbye
{
    NSLog(@"Goodbye");
}
- (Man *)copyWithZone:(NSZone *)zone
{
    //开辟一个新的空间, 创建一个新的对象
    Man *man = [[[self class] allocWithZone:zone] init];
    man.name = self.name;
    man.seual = self.seual;
//    man.name = [self.name copyWithZone:@""];
    man.seual = [self.seual copy];

    return man;
}
//赋值用 在此方法中 编写找不到key值得处理措施  防止产生野指针 所以跟赋值有关使用self 而不是下划线
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    if ([key isEqualToString:@"id"]) {
        self.mId = value;
    }
    if ([key isEqualToString:@"description"]) {
        self.mDescription = value;
    }
}
- (id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}
@end
